package day15.test06;

import java.io.*;
import java.net.Socket;

/**
 * @author Xiao
 * @date 2021/8/9
 */
public class Client06 {
    /**
     * 6. 使用TCP完成文件上传。
     */
    public static void main(String[] args) throws IOException {
        //创建Socket对象，建立连接
        Socket so = new Socket("127.0.0.1", 12121);
        //从本地读入文件到客户端，通过网络写出到服务器
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
                "homework\\src\\day15\\test06\\aa.txt"));
        OutputStream os = so.getOutputStream();
        int b;
        while ((b = bis.read()) != -1) {
            os.write(b);
        }
        bis.close();
        so.shutdownOutput();
        //从服务器读入反馈信息
        BufferedReader br1 = new BufferedReader(new InputStreamReader(so.getInputStream()));
        String s1;
        while ((s1 = br1.readLine()) != null) {
            System.out.println(s1);
        }
        so.close();
    }
}
